﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;

namespace _95_自定义SortedDicitionary集合的排序规则_集合
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedDictionary<string, DateTime> dic = new SortedDictionary<string, DateTime>(new CustSortComparer());

            dic["ab"]=new DateTime(2018,1,1);
            dic["hijklmn"] = new DateTime(2018, 1, 3);
            dic["opqr"] = new DateTime(2018, 1, 5);
            dic["s"] = new DateTime(2018, 1, 7);
            dic["swuvwxyz"] = new DateTime(2018, 1, 9);

            Console.WriteLine("尝试将字典中的各项输出：");
            foreach (var i in dic)
            {
                Console.WriteLine($"{i.Key,-10}-{i.Value}\n");
            }
               

        }
    }

    //自定义比较器，比较两个字符串对象的长度
    public class CustSortComparer : Comparer<string>
    {
        public override int Compare(string x,string y)
        {
            return x.Length - y.Length;
        }
    }

}
